<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\controller;

class AdminArticle extends \app\AdminRest
{
    protected $model;
    protected $sub_list_model;
    protected $sub_data_model;
    protected $field_model;
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
        $this->model = new \app\massage\model\ArticleList();
        $this->sub_list_model = new \app\massage\model\SubList();
        $this->sub_data_model = new \app\massage\model\SubData();
        $this->field_model = new \app\massage\model\FieldList();
    }
    public function fieldList()
    {
        $input = $this->_param;
        $dis[] = ["uniacid", "=", $this->_uniacid];
        if(isset($input["status"])) {
            $dis[] = ["status", "=", 1];
        } else {
            $dis[] = ["status", ">", -1];
        }
        $data = $this->field_model->dataList($dis, $input["limit"]);
        return $this->success($data);
    }
    public function fieldSelect()
    {
        $input = $this->_param;
        $dis[] = ["uniacid", "=", $this->_uniacid];
        $dis[] = ["status", "=", 1];
        $data = $this->field_model->where($dis)->order("top desc,id desc")->select()->toArray();
        return $this->success($data);
    }
    public function fieldInfo()
    {
        $input = $this->_param;
        $dis = ["id" => $input["id"]];
        $data = $this->field_model->dataInfo($dis);
        return $this->success($data);
    }
    public function fieldAdd()
    {
        $input = $this->_input;
        $input["uniacid"] = $this->_uniacid;
        $data = $this->field_model->dataAdd($input);
        return $this->success($data);
    }
    public function fieldUpdate()
    {
        $input = $this->_input;
        $dis = ["id" => $input["id"]];
        $input["uniacid"] = $this->_uniacid;
        $data = $this->field_model->dataUpdate($dis, $input);
        return $this->success($data);
    }
    public function articleList()
    {
        $input = $this->_param;
        $dis[] = ["uniacid", "=", $this->_uniacid];
        if(isset($input["status"])) {
            $dis[] = ["status", "=", 1];
        } else {
            $dis[] = ["status", ">", -1];
        }
        if(!empty($input["title"])) {
            $dis[] = ["title", "like", "%" . $input["title"] . "%"];
        }
        $data = $this->model->dataList($dis, $input["limit"]);
        return $this->success($data);
    }
    public function articleInfo()
    {
        $input = $this->_param;
        $dis = ["id" => $input["id"]];
        $data = $this->model->dataInfo($dis);
        $data["field"] = array_values(array_column($data["field"], "field_id"));
        return $this->success($data);
    }
    public function articleAdd()
    {
        $input = $this->_input;
        $input["uniacid"] = $this->_uniacid;
        $data = $this->model->dataAdd($input);
        return $this->success($data);
    }
    public function articleUpdate()
    {
        $input = $this->_input;
        $dis = ["id" => $input["id"]];
        $input["uniacid"] = $this->_uniacid;
        $data = $this->model->dataUpdate($dis, $input);
        return $this->success($data);
    }
    public function subTitle()
    {
        $input = $this->_param;
        $data = $this->model->getFieldTitle($input["article_id"]);
        return $this->success($data);
    }
    public function subDataList()
    {
        $input = $this->_param;
        $data = $this->model->getFieldTitle($input["article_id"]);
        $diss[] = ["article_id", "=", $input["article_id"]];
        $diss[] = ["status", "=", 1];
        if(!empty($input["start_time"]) && !empty($input["end_time"])) {
            $diss[] = ["create_time", "between", $input["start_time"] . "," . $input["end_time"]];
        }
        $list = $this->sub_list_model->dataList($diss, $input["limit"]);
        if(!empty($list["data"])) {
            $user_model = new \app\massage\model\User();
            foreach ($list["data"] as &$v) {
                $user_info = $user_model->where(["id" => $v["user_id"]])->field("nickName,avatarUrl")->find();
                $v["nickName"] = $user_info["nickName"];
                $v["avatarUrl"] = $user_info["avatarUrl"];
                if(!empty($data)) {
                    foreach ($data as $vs) {
                        $dis = ["field_id" => $vs["field_id"], "sub_id" => $v["id"]];
                        $v[$vs["field_id"]] = $this->sub_data_model->where($dis)->value("value");
                    }
                }
            }
        }
        return $this->success($list);
    }
}

?>